﻿@model PessModel.Archive

@{
    ViewBag.Title = "UploadPaper";
}

<h2 style="width:500px;">Upload Paper</h2>

<div id="operate">
    @Html.ActionLink("Back to My Proposals", "Proposals")
</div>

<div style="clear:both;margin-bottom:20px">
    <h3 style="margin-bottom: 10px">Paper ID: @Model.CalculatedSerialNumber</h3>
    <label style="color:red">Note: The file will be autonamed and the previous file will be overwritten.</label>
</div>

<div>
@section Styles{
    <link href="@Href("~/Content/uploadify.css")" rel="stylesheet" />
}

@section JavaScript{
    <script src="@Href("~/Scripts/jquery.uploadify.js")" type="text/javascript"></script>
    <script type="text/javascript">


    $(function () {
        $('#file_upload').uploadify({
            'fileSizeLimit': 0,
            'swf': '@Url.Content("~/Scripts/uploadify.swf")',
            'uploader': '@Url.Content("~/Attachment/Upload")',
                'auto': true,
                'fileSizeLimit': 0,
                'multi': false,
                'fileTypeExts': '*.doc;*.docx',
                'fileTypeDesc': 'Word Documents',
                'formData': { 'archiveID': '@Model.ID','authCookie': '@(Request.Cookies[FormsAuthentication.FormsCookieName] == null ? string.Empty:Request.Cookies[FormsAuthentication.FormsCookieName].Value)'},
           // 'scriptData': {  }, 
                'buttonText': 'Upload Paper',
                'cancelImg': '@Url.Content("~/images/uploadify-cancel.png")',
            'onQueueComplete': function (file, data, response) {
                //alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
                location.reload(true);
            },
            'onError': function (event, ID, fileObj, errorObj) {
                alert(errorObj.type + ' Error: ' + errorObj.info);
            }
        });
        setDivHeight();
    });
    </script>


}
@*@if ((Roles.IsUserInRole(Membership.GetUser().UserName, "Admin")
    || Roles.IsUserInRole(Membership.GetUser().UserName, "CountyAdmin"))
    && (bool)ViewBag.IsArchiveModificationAllowed)
{
*@<input type="file" name="file_upload" id="file_upload" />
@*}*@
        <div id="showFile" class="displayValue">
        @{
            var grid = new WebGrid(Model.Attachments, defaultSort: "Title");
        }
@*        @grid.GetHtml(columns: from c in grid.Columns(
                 grid.Column("Title", header: " File Name ", format: @<text>@Html.ActionLink((string)item.Title, "Download", "Archive", new { archiveID = Model.ID, title = (string)item.Title }, null)</text>),
                 grid.Column("FileSize", header: " Size（KB） "),
                 grid.Column("TimeStamp", header: " Date Modified "),
                 grid.Column("Operation", header: "Operation", format: @<text>@Html.ActionLink("Delete", "DeleteAttachment", "Archive", new { archiveID = Model.ID, title = (string)item.Title }, null)</text>)
             )
                               where !c.ColumnName.Contains("Operation") || (Roles.IsUserInRole("Admin") || Roles.IsUserInRole("CountyAdmin"))
                               select c
        )*@
            @grid.GetHtml(columns: grid.Columns(
                 grid.Column("Title", header: " File Name "), //format: @<text>@Html.ActionLink((string)item.Title, "Download", "Archive", new { archiveID = Model.ID, title = (string)item.Title }, null)</text>),
                 grid.Column("FileSize", header: " Size（KB） "),
                 grid.Column("TimeStamp", header: " Date Modified "),
                 grid.Column("Operation", header: "Operation", format: @<text>@Html.ActionLink("Download", "Download", "Archive", new { archiveID = Model.ID, title = (string)item.Title }, null)</text>)
            //,grid.Column("Operation", header: "Operation", format: @<text>@Html.ActionLink("Delete", "DeleteAttachment", "Archive", new { archiveID = Model.ID, title = (string)item.Title }, null)</text>)
             )
             )
                              
        </div>
        <br />
</div>